{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "#思路：遍历，遇到一个数就把所有子集加上该数组成新的子集，遍历完毕即是所有子集\n",
    "from typing import List\n",
    "class Solution:\n",
    "    def subsets(self, nums: List[int]) -> List[List[int]]:\n",
    "        out = [[]]\n",
    "        n = len(nums)\n",
    "        for e in nums:\n",
    "            n = len(out)\n",
    "            for j in range(n):\n",
    "                out.append(out[j] + [e])\n",
    "        return out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]\n"
     ]
    }
   ],
   "source": [
    "a = Solution()\n",
    "nums = [1,2,3]\n",
    "print(a.subsets(nums))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
